<?php
class Inventory_Model extends ORM {
	
	protected $table_name = 'inventory';
	protected $primary_key = 'inventory_id';
	protected $col_date = 'inventory_date';
	protected $col_description = 'inventory_description';
	protected $col_status = 'inventory_status';
	protected $col_product_id = 'products_id';
	protected $col_product_name = 'products_name';
	protected $col_product_qty = 'products_qty';
	protected $col_product_weight = 'products_weight';	
	protected $sorting = array('inventory_id' => 'desc');
	
	public function get()
	{
		$this->db->select("*");
		$this->db->from($this->table_name);		
		$this->db->orderby($this->primary_key,'desc');
		$query = $this->db->get();
		return $query->result_array(false);
	}
	
	public function get_by_group()
	{
		$sql = "SELECT *";	
		$sql .= ",DATE_FORMAT(FROM_UNIXTIME(".$this->col_date."),'%m/%d/%y') AS ".$this->col_date.'_group';
		$sql .= ",SUM(".$this->col_product_qty.") AS ".$this->col_product_qty;
		$sql .= " FROM ".$this->table_name;
		$sql .= " GROUP BY ".$this->col_date.'_group';
		$sql .= " ,".$this->col_status;
		$sql .= " ORDER BY ".$this->primary_key.' DESC';
		$query = $this->db->query($sql);
		return $query->result_array(false);
	}
	
	
	public function get_by_product($hd_id = '')
	{
		$sql = "SELECT *";	
		$sql .= ",DATE_FORMAT(FROM_UNIXTIME(".$this->col_date."),'%m/%d/%y') AS ".$this->col_date.'_group';
		$sql .= ",SUM(".$this->col_product_qty.") AS ".$this->col_product_qty;
		$sql .= " FROM ".$this->table_name;
		$sql .= " WHERE ".$this->col_product_id."='".$hd_id."'";
		$sql .= " GROUP BY ".$this->col_date.'_group';
		$sql .= " ,".$this->col_status;
		$sql .= " ,".$this->col_product_id;
		$sql .= " ORDER BY ".$this->primary_key.' DESC';
		$query = $this->db->query($sql);
		return $query->result_array(false);
	}
}
?>